/**
	Pulsar engine. Core.
	Virtual file manager implementation

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

#include <pulsar/pulsar.h>
#include <pulsar/src/pulsar_intr.h>

/**
	Implementation ctor
*/
pl::FileManagerImpl::FileManagerImpl()
{
	return;
}

/**
	Implementation dtor
*/
pl::FileManagerImpl::~FileManagerImpl()
{
	deleteAllObjects();
	return;
}

/**
	Drive ctor
*/
pl::Drive::Drive() :
pl::ListNode<Drive>(*FileManager::_pImpl)
{
	return;
}

/**
	Translation drive ctor
*/
pl::DriveTranslate::DriveTranslate(const pl::Filepath& rootPath, const pl::String<4>& prefix) :
_pDrive(NULL),
_prefix(prefix)
{
	_prefix.lowercase();
	_pDrive = pl::FileManager::_findHandleDrive(rootPath, _root);
	return;
}

/**
	Acepts files for translation disk
*/
bool pl::DriveTranslate::isAccepted(const pl::Filepath& fileName) const
{
	if (fileName.size() < 3 || fileName[3] != PL_T(':'))
	{
		return false;
	}
	if (pl_tolower(fileName[0]) == _prefix[0] && pl_tolower(fileName[1]) == _prefix[1] && pl_tolower(fileName[2]) == _prefix[2])
	{
		return true;
	}
	return false;
}

/**
	Convert translation file name (like exe:\config.txt) to full file name
*/
bool pl::DriveTranslate::handleTrasnlation(pl::Filepath& fileName)
{
	pl::Filepath fileNameRes = pl::mergeFilename(_root, fileName.get(4));
	fileName = fileNameRes;
	return true;
}

//
// End of file 'pulsar_file_manager_impl.cpp'
//
